{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Alignment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import Image\n",
    "from beakerx import *\n",
    "# 1 setAlignmentProviderForColumn defaults\n",
    "colNames = [\"string column\", \"integer column\", \"double column\",\"time column\", \"boolean column\"]\n",
    "row1 = [\"0\", 0, 0, \"1900-01-28 11:00:00\", 0]\n",
    "row2 = [\"June\", 22, 33, \"2004-02-28 12:00:00\", True]\n",
    "row3 = [\"July\", 200, 300, \"2014-03-28 13:00:00\", False]\n",
    "row4 = [\"August\", 222, 333, \"2024-04-28 14:00:00\", True]\n",
    "table1 = TableDisplay(pd.DataFrame([row1, row2, row3, row4], columns=colNames), colNames, ['string', 'integer', 'double', 'time', 'boolean'])\n",
    "table1.setStringFormatForTimes(TimeUnit.DAYS)\n",
    "table1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 1\n",
    "Image(\"../../resources/img/python/tableAPI/cell1_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1_2 setAlignmentProviderForColumn\n",
    "colNames = [\"string column\", \"integer column\", \"double column\",\"time column\", \"boolean column\"]\n",
    "row1 = [\"0\", 0, 0, \"1900-01-28 11:00:00\", 0]\n",
    "row2 = [\"June\", 22, 33, \"2004-02-28 12:00:00\", True]\n",
    "row3 = [\"July\", 200, 300, \"2014-03-28 13:00:00\", False]\n",
    "row4 = [\"August\", 222, 333, \"2024-04-28 14:00:00\", True]\n",
    "table1_2 = TableDisplay(pd.DataFrame([row1, row2, row3, row4], columns=colNames), colNames, ['string', 'integer', 'double', 'time', 'boolean'])\n",
    "table1_2.setStringFormatForTimes(TimeUnit.DAYS)\n",
    "table1_2.setAlignmentProviderForColumn(colNames[0], TableDisplayAlignmentProvider.CENTER_ALIGNMENT)\n",
    "table1_2.setAlignmentProviderForColumn(colNames[1], TableDisplayAlignmentProvider.CENTER_ALIGNMENT)\n",
    "table1_2.setAlignmentProviderForColumn(colNames[2], TableDisplayAlignmentProvider.CENTER_ALIGNMENT)\n",
    "table1_2.setAlignmentProviderForColumn(colNames[3], TableDisplayAlignmentProvider.LEFT_ALIGNMENT)\n",
    "table1_2.setAlignmentProviderForColumn(colNames[4], TableDisplayAlignmentProvider.RIGHT_ALIGNMENT)\n",
    "table1_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 1_2\n",
    "Image(\"../../resources/img/python/tableAPI/cell1_case2.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2 setAlignmentProviderForType\n",
    "colNames = [\"string column\", \"integer column\", \"double column\",\"time column\", \"boolean column\"]\n",
    "row1 = [\"0\", 0, 0, \"1900-01-28 11:00:00\", 0]\n",
    "row2 = [\"June\", 22, 33, \"2004-02-28 12:00:00\", True]\n",
    "row3 = [\"July\", 200, 300, \"2014-03-28 13:00:00\", False]\n",
    "row4 = [\"August\", 222, 333, \"2024-04-28 14:00:00\", True]\n",
    "table2 = TableDisplay(pd.DataFrame([row1, row2, row3, row4], columns=colNames), colNames, ['string', 'integer', 'double', 'time', 'boolean'])\n",
    "table2.setStringFormatForTimes(TimeUnit.DAYS)\n",
    "table2.setAlignmentProviderForType(ColumnType.String, TableDisplayAlignmentProvider.CENTER_ALIGNMENT)\n",
    "table2.setAlignmentProviderForType(ColumnType.Integer, TableDisplayAlignmentProvider.CENTER_ALIGNMENT)\n",
    "table2.setAlignmentProviderForType(ColumnType.Double, TableDisplayAlignmentProvider.CENTER_ALIGNMENT)\n",
    "table2.setAlignmentProviderForType(ColumnType.Time, TableDisplayAlignmentProvider.LEFT_ALIGNMENT)\n",
    "table2.setAlignmentProviderForType(ColumnType.Boolean, TableDisplayAlignmentProvider.RIGHT_ALIGNMENT)\n",
    "table2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 2\n",
    "Image(\"../../resources/img/python/tableAPI/cell2_case1.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Bar Charts Renderer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 3\n",
    "table3 = TableDisplay(pd.read_csv('../../resources/data/interest-rates-small.csv'))\n",
    "table3.setRendererForType(ColumnType.Double, TableDisplayCellRenderer.getDataBarsRenderer(True))\n",
    "#use the false parameter to hide value\n",
    "table3.setRendererForColumn(\"y10\", TableDisplayCellRenderer.getDataBarsRenderer(False))\n",
    "table3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 3\n",
    "Image(\"../../resources/img/python/tableAPI/cell3_case1.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Formatting"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 4\n",
    "df4 = pd.read_csv('../../resources/data/interest-rates-small.csv')\n",
    "df4['time'] = df4['time'].str.slice(0,19).astype('datetime64[ns]')\n",
    "table4 = TableDisplay(df4)\n",
    "table4.setStringFormatForTimes(TimeUnit.DAYS)\n",
    "table4.setStringFormatForType(ColumnType.Double, TableDisplayStringFormat.getDecimalFormat(2,3))\n",
    "table4.setStringFormatForColumn(\"m3\", TableDisplayStringFormat.getDecimalFormat(0, 0))\n",
    "table4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 4\n",
    "Image(\"../../resources/img/python/tableAPI/cell4_case1.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## HTML format\n",
    "\n",
    "HTML format allows markup and styling of the cell's content.  Interactive JavaScript is not supported however."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 5\n",
    "table5 = TableDisplay({'x': '<em style=\"color:red\">italic red</em>',\n",
    "                      'y': '<b style=\"color:blue\">bold blue</b>',\n",
    "                      'z': 'strings without markup work fine too'})\n",
    "table5.setStringFormatForColumn(\"Value\", TableDisplayStringFormat.getHTMLFormat())\n",
    "table5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 5\n",
    "Image(\"../../resources/img/python/tableAPI/cell5_case1.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Column Visibility and Placement"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 6\n",
    "table6 = TableDisplay(pd.read_csv('../../resources/data/interest-rates-small.csv'))\n",
    "#freeze a column\n",
    "table6.setColumnFrozen(\"y1\", True)\n",
    "#hide a column\n",
    "table6.setColumnVisible(\"y30\", False)\n",
    "table6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 6\n",
    "Image(\"../../resources/img/python/tableAPI/cell6_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 7\n",
    "table7 = TableDisplay(pd.read_csv('../../resources/data/interest-rates-small.csv'))\n",
    "#Columns in the list will be shown in the provided order. Columns not in the list will be hidden.\n",
    "table7.setColumnOrder([\"m3\", \"y1\", \"y10\", \"time\", \"y2\"])\n",
    "table7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 7\n",
    "Image(\"../../resources/img/python/tableAPI/cell7_case1.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## HeatmapHighlighter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 8 highlighter for row\n",
    "table8 = TableDisplay(pd.read_csv('../../resources/data/interest-rates-small.csv'))\n",
    "table8.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(\"m3\", TableDisplayCellHighlighter.FULL_ROW))\n",
    "table8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 8\n",
    "Image(\"../../resources/img/python/tableAPI/cell8_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 9 highlighter for column\n",
    "table9 = TableDisplay(pd.read_csv(\"../../resources/data/interest-rates-small.csv\"))\n",
    "table9.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(\"m6\", TableDisplayCellHighlighter.SINGLE_COLUMN, 6, 8, Color.BLACK, Color.PINK))\n",
    "table9.addCellHighlighter(ThreeColorHeatmapHighlighter(\"y1\", TableDisplayCellHighlighter.SINGLE_COLUMN, 4, 6, 8, Color(247,106,106), Color(239,218,82), Color(100,189,122)))\n",
    "table9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 9\n",
    "Image(\"../../resources/img/python/tableAPI/cell9_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 9_2\n",
    "table9.removeAllCellHighlighters()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 9_2\n",
    "Image(\"../../resources/img/python/tableAPI/cell9_case2.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 9_3 set HeatmapHighlighter for type\n",
    "colNames = [\"xxx column\", \"integer column\", \"double column\", \"number column\"]\n",
    "row1 = [6, 6, 0.5, 6]\n",
    "row2 = [3, 3, 2.0, 3]\n",
    "row3 = [2, 2, 3.0, 2]\n",
    "row4 = [0, 0, 6.0, 0]\n",
    "table93 = TableDisplay(pd.DataFrame([row1, row2, row3, row4], columns=colNames), colNames, ['xxx type', 'integer', 'double', 'number'])\n",
    "table93.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(colNames[0], TableDisplayCellHighlighter.SINGLE_COLUMN))\n",
    "table93.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(colNames[1], TableDisplayCellHighlighter.SINGLE_COLUMN))\n",
    "table93.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(colNames[2], TableDisplayCellHighlighter.SINGLE_COLUMN))\n",
    "table93.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(colNames[3], TableDisplayCellHighlighter.SINGLE_COLUMN))\n",
    "table93"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 9_3\n",
    "Image(\"../../resources/img/python/tableAPI/cell9_case3.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## UniqueEntriesHighlighter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 10\n",
    "table10 = TableDisplay(pd.read_csv('../../resources/data/interest-rates-small.csv'))\n",
    "table10.addCellHighlighter(TableDisplayCellHighlighter.getUniqueEntriesHighlighter(\"m3\"))\n",
    "table10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 10\n",
    "Image(\"../../resources/img/python/tableAPI/cell10_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 11\n",
    "table11 = TableDisplay(pd.read_csv('../../resources/data/interest-rates-small.csv'))\n",
    "table11.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(\"m3\", HighlightStyle.SINGLE_COLUMN))\n",
    "table11.addCellHighlighter(TableDisplayCellHighlighter.getHeatmapHighlighter(\"y10\", TableDisplayCellHighlighter.SINGLE_COLUMN))\n",
    "table11.addCellHighlighter(TableDisplayCellHighlighter.getUniqueEntriesHighlighter(\"m6\", HighlightStyle.SINGLE_COLUMN))\n",
    "table11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 11\n",
    "Image(\"../../resources/img/python/tableAPI/cell11_case1.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## FontSize"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 12\n",
    "table12 = TableDisplay(pd.read_csv('../../resources/data/interest-rates-small.csv'))\n",
    "table12.setDataFontSize(10)\n",
    "table12.setHeaderFontSize(16)\n",
    "table12"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 12\n",
    "Image(\"../../resources/img/python/tableAPI/cell12_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 13\n",
    "table13 = TableDisplay(pd.read_csv('../../resources/data/interest-rates-small.csv'))\n",
    "table13.setHeadersVertical(True)\n",
    "table13"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 13\n",
    "Image(\"../../resources/img/python/tableAPI/cell13_case1.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ColorProvider"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 14\n",
    "mapListColorProvider = [\n",
    "    {\"firstCol\":1, \"secondCol\":2, \"thirdCol\":3},\n",
    "    {\"firstCol\":4, \"secondCol\":5, \"thirdCol\":6},\n",
    "    {\"firstCol\":9, \"secondCol\":8, \"thirdCol\":9}\n",
    "]\n",
    "table14 = TableDisplay(mapListColorProvider)\n",
    "\n",
    "colors = [\n",
    "    [Color.LIGHT_GRAY, Color.GRAY, Color.RED],\n",
    "    [Color.DARK_GREEN, Color.ORANGE, Color.RED],\n",
    "    [Color.MAGENTA, Color.BLUE, Color.BLACK]\n",
    "]\n",
    "def color_provider(row, column, table):\n",
    "    return colors[row][column]\n",
    "\n",
    "table14.setFontColorProvider(color_provider)\n",
    "table14"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 14\n",
    "Image(\"../../resources/img/python/tableAPI/cell14_case1.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## ToolTip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 15\n",
    "table15 = TableDisplay(pd.read_csv('../../resources/data/interest-rates-small.csv'))\n",
    "\n",
    "def config_tooltip(row, column, table):\n",
    "      return \"The value is: \" + str(table.values[row][column])\n",
    "\n",
    "table15.setToolTip(config_tooltip)\n",
    "table15"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Image format"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 16_1\n",
    "colNames = [\"Peacock\", \"Morpho\", \"Swallowtail\"]\n",
    "row1 = [\"../../resources/img/butterfly1.jpg\", \"../../resources/img/butterfly2.jpg\", \"../../resources/img/butterfly3.jpg\"]\n",
    "table16_1 = TableDisplay(pd.DataFrame([row1], columns=colNames), colNames)\n",
    "table16_1.setStringFormatForColumn(\"Peacock\", TableDisplayStringFormat.getImageFormat())\n",
    "table16_1.setStringFormatForColumn('Morpho', TableDisplayStringFormat.getImageFormat());\n",
    "table16_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 16_1\n",
    "Image(\"../../resources/img/python/tableAPI/cell16_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 16_2\n",
    "table16_2 = TableDisplay({\"up\": \"\",\n",
    "                        \"down\": \"\"})\n",
    "table16_2.setStringFormatForColumn(\"Value\", TableDisplayStringFormat.getImageFormat())\n",
    "table16_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 16_2\n",
    "Image(\"../../resources/img/python/tableAPI/cell16_case2.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Seamless Update"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 19\n",
    "colNames = [\"a\", \"b\", \"c\"]\n",
    "row1 = [1, 2, 3]\n",
    "row2 = [4, 5, 6]\n",
    "row3 = [7, 8, 9]\n",
    "table19 = TableDisplay(pd.DataFrame([row1, row2, row3], columns=colNames), colNames)\n",
    "table19"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "table19.values[0][0] = 99\n",
    "table19.sendModel()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 19\n",
    "Image(\"../../resources/img/python/tableAPI/cell19_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 19 after sendModel()\n",
    "Image(\"../../resources/img/python/tableAPI/cell19_case2.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Recognized Formats"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 40 (Array of Integers parameter)\n",
    "from beakerx import *\n",
    "\n",
    "TableDisplay({\"a\":100, \"b\":200, \"c\":300})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 40\n",
    "Image(\"../../resources/img/python/tableAPI/cell40_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 41 (2D Array of Integers parameter)\n",
    "TableDisplay([{\"a\":1}, {\"a\":10, \"b\":20}])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 41\n",
    "Image(\"../../resources/img/python/tableAPI/cell41_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 42 (Array of Decimals parameter)\n",
    "TableDisplay({\"a\":1/10, \"b\":1/20, \"c\":0.33})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 42\n",
    "Image(\"../../resources/img/python/tableAPI/cell42_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 43 (2D Array of Decimals parameter)\n",
    "TableDisplay([{\"a\":1/10}, {\"a\":1/100, \"b\":3.12345}])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 43\n",
    "Image(\"../../resources/img/python/tableAPI/cell43_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 44 (Array of Strings parameter)\n",
    "TableDisplay({\"a\":'string aaa', \"b\":'string bbb', \"c\":'string ccc'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 44\n",
    "Image(\"../../resources/img/python/tableAPI/cell44_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 45 (2D Array of Strings parameter)\n",
    "TableDisplay([{\"a\":'a'}, {\"a\":'1a', \"b\":'2b'}])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 45\n",
    "Image(\"../../resources/img/python/tableAPI/cell45_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 46 (Array of Integer Arrays parameter)\n",
    "TableDisplay({\"a\":[1, 2, 3], \"b\":[10, 20, 30], \"c\":[100, 200, 300]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 46\n",
    "Image(\"../../resources/img/python/tableAPI/cell46_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 47 (2D Array of Integer Arrays parameter)\n",
    "TableDisplay([\n",
    "    {\"a\":[1, 2, 3]}, \n",
    "    {\"a\":[10, 20, 30], \"b\":[100, 200, 300]}])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 47\n",
    "Image(\"../../resources/img/python/tableAPI/cell47_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 48 (2D Array of Integer,Decimal,String,Array Arrays parameter)\n",
    "row1 = {\"a\":100, \"b\":200, \"c\":300}\n",
    "row2 = {\"a\":1/10, \"b\":1/20, \"c\":0.33}\n",
    "row3 = {\"a\":'a a a', \"b\":'b b b', \"c\":'c c c'}\n",
    "row4 = {\"a\":[1, 2, 3], \"b\":[10, 20, 30], \"c\":[100, 200, 300]}\n",
    "TableDisplay([row1, row2, row3, row4])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 48\n",
    "Image(\"../../resources/img/python/tableAPI/cell48_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 49 ([Integer,Decimal,String,Array] parameter)\n",
    "TableDisplay({\"a\":100, \"b\":1/20, \"c\":'c c c', \"d\":[100, 200, 300]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 49\n",
    "Image(\"../../resources/img/python/tableAPI/cell49_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 50 (2D Arrays of [Integer,Decimal,String,Array] parameter)\n",
    "row1 = {\"a\":10, \"b\":1/10, \"c\":'c', \"d\":[100, 200]}\n",
    "row2 = {\"a\":100, \"b\":1/20, \"c\":'c c c', \"d\":[100, 200, 300]}\n",
    "TableDisplay([row1, row2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 50\n",
    "Image(\"../../resources/img/python/tableAPI/cell50_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 51 (numbers as name of Array keys (Array parameter))\n",
    "TableDisplay({10:20, 1/10:1/20, 'c':'c c c', '[100, 200]':[100, 200, 300]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 51\n",
    "Image(\"../../resources/img/python/tableAPI/cell51_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 52 (numbers as name of Array keys (2D Array parameter)\n",
    "row1 = {40:40, 1/40:1/40, 'c':'c'}\n",
    "row2 = {40:20, 1/40:1/20, 'c':'c c c', '[100, 200]':[100, 200, 300]}\n",
    "TableDisplay([row1, row2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 52\n",
    "Image(\"../../resources/img/python/tableAPI/cell52_case1.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Python API for Table Display\n",
    "\n",
    "In addition to APIs for creating and formatting BeakerX's interactive table widget, the Python runtime configures pandas to display tables with the interactive widget instead of static HTML."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 53\n",
    "import pandas as pd\n",
    "from beakerx import *\n",
    "\n",
    "df = pd.DataFrame({\"runway\": [\"24\", \"36L\"]})\n",
    "\n",
    "TableDisplay(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 53\n",
    "Image(\"../../resources/img/python/tableAPI/cell53_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from beakerx import *\n",
    "from beakerx.object import beakerx\n",
    "#Display mode: TableDisplay Widget\n",
    "beakerx.pandas_display_table()\n",
    "\n",
    "pd.DataFrame(data=np.zeros((5,5)), index=pd.Int64Index([0, 1, 2, 3, 4], dtype='int64'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 54\n",
    "pd.read_csv('../../resources/data/pd_index.csv', index_col=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 54\n",
    "Image(\"../../resources/img/python/tableAPI/cell54_case1.png\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 55\n",
    "pd.read_csv('../../resources/data/interest-rates-small.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result of cell 55\n",
    "Image(\"../../resources/img/python/tableAPI/cell55_case1.png\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Rows to show"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "tableRTS = TableDisplay(pd.read_csv('../../resources/data/interest-rates.csv'))\n",
    "tableRTS.setRowsToShow(RowsToShow.SHOW_10)\n",
    "tableRTS"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## The length of types should be same as number of cols."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# expected result is error message\n",
    "colNames = [\"column 1\", \"column 2\", \"column 3\"]\n",
    "row1 = [6, 6, 0.5]\n",
    "row2 = [3, 3, 2.0]\n",
    "table94 = TableDisplay(pd.DataFrame([row1, row2], columns=colNames), colNames, [\"integer\", \"double\" ])\n",
    "table94"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Set global timezone"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from beakerx import *\n",
    "TableDisplay.timeZoneGlobal = \"Europe/London\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "tableGTZ = TableDisplay(pd.read_csv('../../resources/data/interest-rates.csv'))\n",
    "tableGTZ"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "tableGTZ.setTimeZone(\"America/Los_Angeles\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# color provider\n",
    "mapListColorProvider = [\n",
    "    {\"a\": 1, \"b\": 2, \"c\": 3},\n",
    "    {\"a\": 4, \"b\": 5, \"c\": 6},\n",
    "    {\"a\": 7, \"b\": 8, \"c\": 5}\n",
    "]\n",
    "table56 = TableDisplay(mapListColorProvider)\n",
    "\n",
    "def color_provider(row, column, td):\n",
    "    row = td.values[row]\n",
    "    val = row[column]\n",
    "    if val == 5:\n",
    "        return Color.GREEN    \n",
    "    return Color.BLACK    \n",
    "\n",
    "table56.setFontColorProvider(color_provider)\n",
    "table56"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": false,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": false,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
